﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using ScrumTable.Common;
using ScrumTable.Common.Collections;
using ScrumTable.DL.Data.Common;
using ScrumTable.DL.Data.Generic.Cache;
using ScrumTable.DL.Data.Schema;
using ScrumTable.DL.Data.Schema.ScrumTableV1;

#endregion

namespace ScrumTable.DL.Data.Generic
{
    /// <summary>
    /// This class contains the save error information provided by the underlying
    /// data driver occurred during the save procedure.
    /// </summary>
    public class DataSyncErrorInfo : IDataSyncErrorInfo
    {
        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------

        private readonly CacheSaveError _innerError;

        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        /// <summary>
        /// Gets the name of the back-end field which has caused the error.
        /// </summary>
        public string FieldMappedName { get { return _innerError.FieldMappedName; } }

        /// <summary>
        /// Gets a human readable name of the back-end field which has caused the error.
        /// </summary>
        public string FieldDisplayName { get { return _innerError.FieldDisplayName; } }

        /// <summary>
        /// Gets the reason of a field error.
        /// </summary>
        public DataSyncErrorReason FieldErrorReason { get { return EnumUtil.Convert<CacheSaveErrorReason, DataSyncErrorReason>(_innerError.FieldErrorReason); } }

        /// <summary>
        /// Gets the fields original value.
        /// </summary>
        public object OriginalValue { get { return _innerError.OriginalValue; } }

        /// <summary>
        /// Gets the field value.
        /// </summary>
        public object Value { get { return _innerError.Value; } }

        /// <summary>
        /// Gets the exception which has caused the error.
        /// </summary>
        public Exception Error { get { return _innerError.Error; } }

        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance of the <see cref="DataSyncErrorInfo"/> class.
        /// </summary>
        /// <param name="saveError">Specifies the name of the backend field which has caused the error.</param>
        internal DataSyncErrorInfo(CacheSaveError saveError)
        {
            PreCondition.AssertNotNull(saveError, "saveError");

            _innerError = saveError;
        }

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        #endregion

        #region Events
        //--------------------------------------------------------------------
        // Events
        //--------------------------------------------------------------------
        #endregion

    }
}